import axios from "axios";

/**
 * 通用的请求方法,
 * @param method
 * @param url
 * @param params
 * @returns {*}
 */
const req = (method,url,params) => {
  return axios({
    method: method,
    url: url,
    headers: {
      'Content-Type': 'application/json',
      token: localStorage.getItem('logintoken')
    },
    data: params,
    traditional: true,
    transformRequest: [
      function (data,headers) {
        let ret = ''
        for (let it in data) {
          ret +=
            encodeURIComponent(it) +
            '=' +
            encodeURIComponent(data[it]) +
            '&'
        }
        console.log('请求前格式化参数',headers,data,ret);
        return ret
      }
    ]
  }).then(res => {
    console.log('Response:',res);
    return res.data;
  });
}, openReq = () => {

};

export {
  req
  ,openReq
}
